//
//  WarMap.h
//  DiceWar
//
//  Created by Xiao  Feng on 17/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef GAME_GAMEPLAY_HEXMAP_H_
#define GAME_GAMEPLAY_HEXMAP_H_

#include "HexMapGrid.h"
#include "HexMapGeneratingStrategy.h"
#include "MathUtil.h"
#include "StaticMatrix.h"
#include "Player.h"
#include "cocos2d.h"
#include <map>

class HexMap
{
public:
    HexMap();
    ~HexMap();
    
private:
    HexMap(const HexMap& other);
    HexMap& operator=(const HexMap& other);
    
public:
    typedef StaticMatrix<HexMapGrid, gameConstants::kHexMapSizeX, gameConstants::kHexMapSizeY> HexMapGridMatrix;
    typedef HexMapGridMatrix::const_iterator MatrixConstIter;
    typedef HexMapGridMatrix::iterator MatrixIter;
    friend class HexMapGeneratingStrategyNormal;
    
    void init(int numPlayers);
    void generate(int numPlayers);
    
    void setMapGrid(int xIndex, int yIndex, const HexMapGrid& grid);
    const HexMapGrid& getMapGrid(int xIndex, int yIndex) const;
    HexMapGrid& getMapGrid(int xIndex, int yIndex);
    
    cocos2d::CCPoint getMapGridPosition(int coordinateX, int coordinateY) const;
    
    /** to return the number of cells owned by the player with specified player type
     */
    int getNumPlayerCells(PlayerType type) const;
    
    /** check if the cell at the given position is occupied by the given player type
     */
    bool isCellOcupiedByPlayer(int xIndex, int yIndex, PlayerType type) const;
    
    /** check if the map is seperated into different parts
     */
    bool isMapSinglePiece() const;
    
    void addDicesRandomlyToPlayer(int numDicesToAdd, PlayerType type);
    
    /** functions for input to use
     */
    HexCellCoordinate getMapGridCoordinate(const cocos2d::CCPoint& point) const;
    
    void reset();
    
private:
    int getNumStartDicesFromNumPlayers(int numPlayers);
    
private:
    HexMapGridMatrix m_map;
};



#endif //GAME_GAMEPLAY_HEXMAP_H_
